package com.pro.controller;

import com.pro.mapper.CensusMapper;
import com.pro.pojo.Census;
import com.pro.pojo.JsonData;
import com.pro.pojo.ProductCategroy;
import com.pro.service.CensusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * auther 杨沛琪
 * createDate 2022/1/21
 */
@Controller
@RequestMapping("/Census")
public class CensusController {
    @Autowired
    private CensusService censusService;

    //课程统计
    @RequestMapping("/getCourseCensus")
    @ResponseBody
    public JsonData getCensus(Census census){
        List<Census> countCourse = null;
        try {
            countCourse = censusService.getCensus(census);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return countCourse.size() > 0 ? JsonData.buildSuccess(countCourse) : JsonData.buildError("没有查询到数据");
    }


    //获取商品名称
    @RequestMapping("/getTitle")
    @ResponseBody
    public JsonData getTitle(){
        List<ProductCategroy> title = censusService.getTitle();
        return title!=null?JsonData.buildSuccess(title):JsonData.buildError("服务器错误");
    }

    //获取商品点击次数
    @RequestMapping("/getHits")
    @ResponseBody
    public JsonData getHits(){
        List<ProductCategroy> title = censusService.getHits();
        return title!=null?JsonData.buildSuccess(title):JsonData.buildError("服务器错误");
    }

    //获取商品收藏次数
    @RequestMapping("/getCollection")
    @ResponseBody
    public JsonData getCollection(){
        List<ProductCategroy> title = censusService.getCollection();
        return title!=null?JsonData.buildSuccess(title):JsonData.buildError("服务器错误");
    }

    //统计关键字
    @RequestMapping("/getGetKeyword")
    @ResponseBody
    public JsonData getGetKeyword() {
        List<Map<String, Object>> getKeyword = censusService.getGetKeyword();
        return getKeyword != null ? JsonData.buildSuccess(getKeyword) : JsonData.buildError("服务器错误");
    }
    //获取商品订单数  
    /*
    * @author Ypq
    * @date 2022/2/10 14:48
    * @return com.pro.pojo.JsonData
    */        
    @RequestMapping("/getCommodityOrderNum")
    @ResponseBody
    public JsonData getCommodityOrderNum(){
        List<Census> orderNum = censusService.getOrderNum();
        JsonData jsonData = new JsonData();
        return orderNum!=null?jsonData.buildSuccess(orderNum):JsonData.buildError("后台数据错误");
    }

    //获取课程订单数  
    /*
    * @author Ypq
    * @date 2022/2/10 14:48
    * @return com.pro.pojo.JsonData
    */        
    @RequestMapping("/getCourseOrderNum")
    @ResponseBody
    public JsonData getCourseOrderNum(){
        List<Census> orderNum = censusService.getCourseOrderNum();
        JsonData jsonData = new JsonData();
        return orderNum!=null?jsonData.buildSuccess(orderNum):JsonData.buildError("后台数据错误");
    }
    //获取商品评论
    /*
     * @author Ypq
     * @date 2022/2/10/14:01
     * @return com.pro.pojo.Census
     */
    @RequestMapping("/getCommodityCommentNum")
    @ResponseBody
    public JsonData getCommodityCommentNum(){
        List<Census> commodityCommentNum = censusService.getCommodityCommentNum();
        JsonData jsonData = new JsonData();
        return commodityCommentNum!=null?jsonData.buildSuccess(commodityCommentNum):JsonData.buildError("后台数据错误");
    }

    //获取课程评论
    /*
    * @author Ypq
    * @date 2022/2/10 14:23
    * @return com.pro.pojo.Census
    */        
    @RequestMapping("/getCourseCommentNum")
    @ResponseBody
    public JsonData getCourseCommentNum(){
        List<Census> courseCommentNum = censusService.getCourseCommentNum();
        JsonData jsonData = new JsonData();
        return courseCommentNum!=null?jsonData.buildSuccess(courseCommentNum):JsonData.buildError("后台数据错误");
    }

    //获取微圈评论
    /*
    * @author Ypq
    * @date 2022/2/10 14:47
    * @return com.pro.pojo.JsonData
    */        
    @RequestMapping("/getArticleCommentNum")
    @ResponseBody
    public JsonData getArticleCommentNum(){
        List<Census> articleCommentNum = censusService.getArticleCommentNum();
        JsonData jsonData = new JsonData();
        return articleCommentNum!=null?jsonData.buildSuccess(articleCommentNum):JsonData.buildError("后台数据错误");
    }

    //统计前端人数
    /*
    * @author Ypq
    * @date 2022/2/16 9:02
    * @return com.pro.pojo.JsonData
    */        
    @RequestMapping("/getFrontEndNumber")
    @ResponseBody
    public JsonData getFrontEndNumber() {
        Integer frontEndNumber = censusService.getFrontEndNumber("js_before_user");
        return frontEndNumber > 0 ? JsonData.buildSuccess(frontEndNumber) : JsonData.buildError("服务器错误");
    }
    //统计后端人数
    /*
    * @author Ypq
    * @date 2022/2/16 9:02
    * @return com.pro.pojo.JsonData
    */        
    @RequestMapping("/getBackEndNumber")
    @ResponseBody
    public JsonData getBackEndNumber() {
        Integer frontEndNumber = censusService.getFrontEndNumber("js_user");
        return frontEndNumber > 0 ? JsonData.buildSuccess(frontEndNumber) : JsonData.buildError("服务器错误");
    }

    //统计一个月之内前端人数
    /*
    * @author Ypq
    * @date 2022/2/16 9:03
    * @return com.pro.pojo.JsonData
    */        
    @RequestMapping("/getFrontMonthlyNumber")
    @ResponseBody
    public JsonData getFrontMonthlyNumber() {
        List monthlyNumber = censusService.getMonthlyNumber("js_before_user","create_date");
        return monthlyNumber != null ? JsonData.buildSuccess(monthlyNumber) : JsonData.buildError("服务器错误");
    }
    //统计一个月之内后端人数
    /*
    * @author Ypq
    * @date 2022/2/16 9:03
    * @return com.pro.pojo.JsonData
    */        
    @RequestMapping("/getAfterMonthlyNumber")
    @ResponseBody
    public JsonData getAfterMonthlyNumber() {
        List monthlyNumber = censusService.getMonthlyNumber("js_user","register_date");
        return monthlyNumber != null ? JsonData.buildSuccess(monthlyNumber) : JsonData.buildError("服务器错误");
    }

   
}
